<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - multiclass_tools.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2010  Davis E. King (davis@dlib.net)
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_MULTICLASS_TOoLS_Hh_
<font color='#0000FF'>#define</font> DLIB_MULTICLASS_TOoLS_Hh_

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='multiclass_tools_abstract.h.html'>multiclass_tools_abstract.h</a>"

<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>vector<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>set<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../unordered_pair.h.html'>../unordered_pair.h</a>"

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> label_type<font color='#5555FF'>&gt;</font>
    std::vector<font color='#5555FF'>&lt;</font>label_type<font color='#5555FF'>&gt;</font> <b><a name='select_all_distinct_labels'></a>select_all_distinct_labels</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>label_type<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> labels
    <font face='Lucida Console'>)</font>
    <b>{</b>
        std::set<font color='#5555FF'>&lt;</font>label_type<font color='#5555FF'>&gt;</font> temp;
        temp.<font color='#BB00BB'>insert</font><font face='Lucida Console'>(</font>labels.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, labels.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> std::vector<font color='#5555FF'>&lt;</font>label_type<font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>temp.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, temp.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> label_type, <font color='#0000FF'>typename</font> U<font color='#5555FF'>&gt;</font>
    std::vector<font color='#5555FF'>&lt;</font>unordered_pair<font color='#5555FF'>&lt;</font>label_type<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> <b><a name='find_missing_pairs'></a>find_missing_pairs</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::map<font color='#5555FF'>&lt;</font>unordered_pair<font color='#5555FF'>&lt;</font>label_type<font color='#5555FF'>&gt;</font>,U<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> bdfs 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>typedef</font> std::map<font color='#5555FF'>&lt;</font>unordered_pair<font color='#5555FF'>&lt;</font>label_type<font color='#5555FF'>&gt;</font>,U<font color='#5555FF'>&gt;</font> map_type;

        <font color='#009900'>// find all the labels
</font>        std::set<font color='#5555FF'>&lt;</font>label_type<font color='#5555FF'>&gt;</font> temp;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'>typename</font> map_type::const_iterator i <font color='#5555FF'>=</font> bdfs.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; i <font color='#5555FF'>!</font><font color='#5555FF'>=</font> bdfs.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            temp.<font color='#BB00BB'>insert</font><font face='Lucida Console'>(</font>i<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>first.first<font face='Lucida Console'>)</font>;
            temp.<font color='#BB00BB'>insert</font><font face='Lucida Console'>(</font>i<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>first.second<font face='Lucida Console'>)</font>;
        <b>}</b>

        std::vector<font color='#5555FF'>&lt;</font>unordered_pair<font color='#5555FF'>&lt;</font>label_type<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> missing_pairs;

        <font color='#009900'>// now make sure all label pairs are present
</font>        <font color='#0000FF'>typename</font> std::set<font color='#5555FF'>&lt;</font>label_type<font color='#5555FF'>&gt;</font>::const_iterator i, j;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> temp.<font color='#BB00BB'>begin</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; i <font color='#5555FF'>!</font><font color='#5555FF'>=</font> temp.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> i, <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j; j <font color='#5555FF'>!</font><font color='#5555FF'>=</font> temp.<font color='#BB00BB'>end</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>const</font> unordered_pair<font color='#5555FF'>&lt;</font>label_type<font color='#5555FF'>&gt;</font> <font color='#BB00BB'>p</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>i, <font color='#5555FF'>*</font>j<font face='Lucida Console'>)</font>;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>bdfs.<font color='#BB00BB'>count</font><font face='Lucida Console'>(</font>p<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                    missing_pairs.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font>p<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'>return</font> missing_pairs;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_MULTICLASS_TOoLS_Hh_
</font>


</pre></body></html>